
{% extends "base.html" %}

{% block title %}订阅管理{% endblock %}

{% block head %}
{% endblock %}

{% block content %}
    <p id = 'SelectedValue' style="display: none">存放下拉列表框选中的值，不显示</p>
    <fieldset class="layui-elem-field layui-field-title" style="text-align: center;margin-top: 30px;">
        <legend>订阅管理</legend>
    </fieldset>
    <div class="layui-row" style="text-align: center">
        <table class="layui-hide layui-anim layui-anim-fadein" id="Newspaper_t" lay-filter="newspaper" >
        </table>
    </div>
    {#报刊表单头部工具栏弹窗#}
    <div style="height: 100px; margin: 5%; display: none" id="search_info_form">
        <form class="layui-form" id="search_forms" method="post" lay-filter="example">
            <div class="layui-form-item">
                <label class="layui-form-label">筛选值</label>
                <div class="layui-input-block">
                    <select id="search_selector" lay-filter="search_list_1">
                        <option value=""></option>
                        <option value="1">报刊ID</option>
                        <option value="2">报刊名</option>
                        <option value="3">报刊价格</option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">价格区间</label>
                <div class="layui-input-block">
                    <select id="price_zone_selector" lay-filter="price_list" disabled="disabled">
                        <option value=""></option>
                        <option value="1">10元以下</option>
                        <option value="2">10元至30元</option>
                        <option value="3">30元以上</option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">搜索值</label>
                <div class="layui-input-block">
                    <input type="text" id="search_form" name="bid" lay-verify="title" autocomplete="off"
                           placeholder="请输入信息" class="layui-input">
                </div>
            </div>
        </form>
    </div>
    {#退订表单板块#}
    <div style="margin: 5%; display: none" id="add_unsubscribe_form">
        <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
            <legend>已订阅表单</legend>
        </fieldset>
        <h1 style="margin-top: 20px;text-align: center">
            退订报刊ID：<span id = 'newspaperID_Unsubscribe'></span>
            退订报刊名：<span id = 'newspaperName_Unsubscribe'></span>
        </h1>
        <div>
            {#退订表单头部工具栏功能#}
            <div>
                <form class="layui-form layui-inline" id="search_unsubscribe_forms" method="post" lay-filter="search_unsubscribe">
                    <div class="layui-form-item layui-inline">
                        <label class="layui-form-label">筛选值</label>
                        <div class="layui-input-block">
                            <select id="search_unsubscribe_selector" lay-filter="search_unsubscribe_list">
                                <option value=""></option>
                                <option value="0">用户ID</option>
                                <option value="1">用户名</option>
                                <option value="2">部门ID</option>
                                <option value="3">部门名</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-form-item layui-inline">
                        <label class="layui-form-label">搜索值</label>
                        <div class="layui-input-block">
                            <input type="text" id="search_unsubscribe_form" name="unsubscribe_bid" lay-verify="title" autocomplete="off"
                                   placeholder="请输入信息" class="layui-input">
                        </div>
                    </div>
                </form>
                <div class="layui-form-item layui-inline">
                    <div class="layui-btn-container">
                        <button class="layui-btn  layui-btn-normal" id ="seekUnsubscribeData">查找信息</button>
                    </div>
                </div>
            </div>
            {#退订表单#}
            <table class="layui-hide" style="text-align: center" lay-filter="unsubscribe_table" id = 'Unsubscribe_t'></table>
            {#退订按钮#}
            <div class="layui-btn-group demoTable">
                <button class="layui-btn layui-btn-danger" id="unsubscribe_button" data-type="Unsubscribe">退订</button>
            </div>
        </div>
    </div>
    {#部门订阅表单板块#}
    <div style="margin: 5%; display: none" id="add_department_form">
        <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;text-align: center">
            <legend>部门订阅表单</legend>
        </fieldset>
        <h1 style="margin-top: 20px;text-align: center">
            订阅报刊ID：<span id = 'newspaperID_Department'></span>
            订阅报刊名：<span id = 'newspaperName_Department'></span>
        </h1>
        <div>
            {#头部工具栏内容#}
            <div>
                <form class="layui-form layui-inline" id="search_department_forms" lay-filter="search_department">
                    <div class="layui-form-item layui-inline">
                        <label class="layui-form-label">筛选值</label>
                        <div class="layui-input-block">
                            <select id="search_department_selector" lay-filter="search_department_list" name = "select_department">
                                <option value=""></option>
                                <option value="0">部门ID</option>
                                <option value="1">部门名</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-form-item layui-inline">
                        <label class="layui-form-label">搜索值</label>
                        <div class="layui-input-block">
                            <input type="text" id="search_department_form" name="department_bid" autocomplete="off"
                                   placeholder="请输入信息" class="layui-input">
                        </div>
                    </div>
                </form>
                <div class="layui-inline">
                    <button class="layui-btn layui-btn-sm  layui-btn-normal" id="seekDepartmentData">查找信息</button>
                </div>
            </div>
            {#部门订阅表单#}
            <table class="layui-hide" style="text-align: center" lay-filter="department_table" id = 'Department_t'></table>
            {#部门订阅按钮#}
            <div class="layui-btn-group">
                <button class="layui-btn layui-btn-danger" id="department_button">订阅</button>
            </div>
        </div>
    </div>
    {#员工订阅表单板块#}
    <div style="margin: 5%; display: none" id="add_employee_form">
        <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
            <legend>员工订阅表单</legend>
        </fieldset>
        <h1 style="margin-top: 20px;text-align: center">
            订阅报刊ID：<span id = 'newspaperID_Employee'></span>
            订阅报刊名：<span id = 'newspaperName_Employee'></span>
        </h1>
        <div>
            <div>
                <form class="layui-form layui-inline" id="search_employee_forms" method="post" lay-filter="search_employee">
                    <div class="layui-form-item layui-inline">
                        <label class="layui-form-label">筛选值</label>
                        <div class="layui-input-block">
                            <select id="search_employee_selector" lay-filter="search_employee_list">
                                <option value=""></option>
                                <option value="0">用户ID</option>
                                <option value="1">用户名</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-form-item layui-inline">
                        <label class="layui-form-label">搜索值</label>
                        <div class="layui-input-block">
                            <input type="text" id="search_employee_form" name="employee_bid" lay-verify="title" autocomplete="off"
                                   placeholder="请输入信息" class="layui-input">
                        </div>
                    </div>
                </form>
                <div class="layui-btn-container layui-inline">
                    <button class="layui-btn layui-btn-sm  layui-btn-normal" id="seekEmployeeData">查找信息</button>
                </div>
            </div>
            <table class="layui-hide"  style="text-align: center" lay-filter="employee_table" id = 'Employee_t'></table>
            <div class="layui-btn-group demoTable">
                <button class="layui-btn layui-btn-danger" id="employee_button" lay-filter="employee" data-type="Subscribe_Employee">订阅</button>
            </div>
        </div>
    </div>
    {#报刊表单头部工具栏#}
    <script type="text/html" id="newspaper_toolbar">
        <div class="layui-btn-container">
            <button class="layui-btn layui-btn-sm  layui-btn-normal" lay-event="seekNewspaperData">查找信息</button>
        </div>
    </script>
    {#报刊表单右侧工具栏#}
    <script type="text/html" id="barDemo">
        <a class="layui-btn layui-btn-sm" lay-event="subscribe-department">部门订阅</a>
        <a class="layui-btn layui-btn-sm" lay-event="subscribe-employee">员工订阅</a>
        <a class="layui-btn layui-btn-danger layui-btn-sm" lay-event="unsubscribe">退订</a>
    </script>

    {#报刊表单#}
     <fieldset class="layui-elem-field layui-field-title" style="text-align: center;margin-top: 30px;">
        <legend>订阅表单</legend>
    </fieldset>
    <div class="layui-row" style="text-align: center">
        <table class="layui-hide layui-anim layui-anim-fadein" id="order_info" lay-filter="order" >
        </table>
    </div>
{% endblock %}

{% block script %}
    <script>
        var table = layui.table;
        var $ = layui.jquery;
        var form = layui.form;
        //报刊表格设计
        var option_order = {
            elem: '#order_info'
            , title: '订单数据表'
            ,data:''
            , cols: [[
                  {field: 'UserName', title: '用户名', align: 'center'}
                , {field: 'NewspaperName', title: '报刊名', align: 'center'}
                , {field: 'DepartmentName', title: '部门名', align: 'center'}
                , {field: 'Number', title: '订阅数量', align: 'center'}
                , {field: 'CreateTime', title: '加入时间', align: 'center'}
            ]]
            , limit:10
            , page: true
        };
        //报刊表格设计
        var option = {
            elem: '#Newspaper_t'
            , toolbar: '#newspaper_toolbar'
            , title: '用户数据表'
            ,data:''
            , cols: [[
                {field: 'NewspaperID', title: '报纸ID', align: 'center', fixed: 'left', sort: true, width:270}
                , {field: 'NewspaperName', title: '报刊名', align: 'center', width:270}
                , {field: 'Price', title: '报刊价格', align: 'center', width:270}
                , {field: 'OtherInfo', title: '报刊信息', align: 'center', width:270}
                , {field: 'CreateTime', title: '加入时间', align: 'center', width:270}
                , {field: 'RowTools', fixed: 'right', title: '操作', toolbar: '#barDemo', width:300}
            ]]
            , limit:20
            , page: true
        };
        //退订表格设计
        var option_unsubscribe = {
            elem: '#Unsubscribe_t'
            ,toolbar: '#unsubscribe_toolbar'
            , data:''
            , cols: [[
                { type: 'checkbox',fixed: 'left',align: 'center', width:180 }
                , { field: 'UserID',  title: '用户ID',fixed: 'left',align: 'center', width:180}
                , { field: 'UserName',  title: '人名' , align: 'center',width:180}
                , { field: 'DepartmentID',  title: '部门ID' , align: 'center',width:180}
                , { field: 'DepartmentName',  title: '部门名' , align: 'center',width:180}
                , { field: 'CreateTime',  title: '订阅时间', align: 'center',width:180}
                , { field: 'Number', title: '订阅数量',fixed: 'right', align: 'center',width:180}
            ]]
            , page: true
        };
        //部门订阅表格设计
        var option_department = {
            elem: '#Department_t'
            ,toolbar: '#department_toolbar'
            ,cellMinWidth: 80
            ,data:''
            , cols: [[
                { type: 'checkbox',fixed: 'left' }
                , { field: 'DepartmentID', title: '部门ID',fixed: 'left', align: 'center', sort: true ,width:350}
                , { field: 'DepartmentName', title: '部门名', sort: true , align: 'center',width:350}
                , { field: 'Number',  title: '订阅数量', align: 'center',edit: 'text',fixed: 'right',width:350}
            ]]
            , page: true
            , text: {
                Number: 0
            }
        };
        //员工订阅表格设计
        var option_employee = {
            elem: '#Employee_t'
            , toolbar: '#employee_toolbar'
            , cellMinWidth: 80
            , data: ''
            , cols: [[
                {type: 'checkbox',fixed: 'left'}
                , {field: 'UserID', title: '员工ID', sort: true, align: 'center',width:350}
                , {field: 'UserName', title: '员工名', align: 'center',width:350}
                , {field: 'Number', title: '订阅数量', edit: 'text',fixed: 'right', align: 'center',width:350}
            ]]
            , page: true
            , text: {
                Number: 0
            }
        };

        //加载报刊表格
        load_table('{{ url_for('main_api.get_newspaper_all_info') }}',option);
        load_table('{{ url_for('main_api.get_order_all_info') }}', option_order);

        //异步接口加载表格
        function load_table(URL,option) {
            $.ajax({
                url:URL,
                type: 'GET',
                async: true,
                success: function (res) {
                    if (res.code === '200' || res.code === '2001') {
                        var data = res.data;
                        load_rows(data,option);
                    } else {
                        layer.msg(res.msg);
                    }
                },
                error: function f(res) {
                    alert("请求失败！状态码：" + res.status);
                }
            })
        }
        //异步接口加载退订表格表格
        function load_unsubscribe_table(URL,option) {
            var NewspaperID = $("#newspaperID_Unsubscribe").text();
            $.ajax({
                url:URL,
                type: 'GET',
                async: true,
                data:{
                    'tag': "报纸ID",
                    'keyword': NewspaperID
                },
                success: function (res) {
                    if (res.code === '200' || res.code === '2001') {
                        var data = res.data;
                        load_rows(data,option);
                    } else {
                        layer.msg(res.msg);
                    }
                },
                error: function f(res) {
                    alert("请求失败！状态码：" + res.status);
                }
            })
        }

        //加载数据
        function load_rows(data,option) {
            var table = layui.table;
            data_length = data.length;
            option['data'] = data;
            table.render(option);
        }

        //头工具栏事件
        table.on('toolbar(newspaper)', function(obj){
            var checkStatus = table.checkStatus(obj.config.id);
            switch(obj.event){
                case 'seekNewspaperData':
                    var tag_name, keyword;
                    layer.open({
                        type: 1,
                        title:"查找信息",
                        btn: ['查找'],
                        shadeClose: true,
                        shade: 0,
                        area:['400px', '350px'],
                        content: $("#search_info_form"),
                        success:function(layero, index){
                            $('#search_selector').val("");
                            $('#search_form').val("");
                            form.render('select')
                            form.on('select(search_list_1)', function (data) {
                                tag_name = data.elem[data.elem.selectedIndex].text;
                                if (tag_name === '报刊价格') {
                                    $('#price_zone_selector').removeAttr("disabled");
                                }
                                if (tag_name === '报刊ID') {
                                    $('#price_zone_selector').prop("disabled", 'disabled');
                                }
                                if (tag_name === '报刊名') {
                                    $('#price_zone_selector').prop("disabled", 'disabled');
                                }
                                form.render('select');
                            });
                            form.render('select');
                        },
                        yes:function (ind) {
                            var index = layer.load(1);
                            keyword = $('#search_form').val();
                            $('#search_info_form').css('display', 'none');
                            if (tag_name === '报刊价格') {
                                keyword = $('#price_zone_selector').val();
                                if (keyword === '1') {
                                    keyword = '0,10'
                                } else if (keyword === '2') {
                                    keyword = '10,30'
                                } else {
                                    keyword = '30, 100000'
                                }
                            }
                            $('#search_info_form').css('display', 'none');
                            $.ajax({
                                url:'{{ url_for('main_api.get_newspaper_info_by_tags') }}',
                                type:'GET',
                                async:true,
                                data:{'tag': tag_name, 'keyword': keyword},
                                success:function (res) {
                                    if(res.code === '200'){
                                        var data = res.data;
                                        option['data'] = data;
                                        table.render(option);
                                        layer.msg('共查找到' + data.length + '条记录');
                                        layer.close(index);
                                    }
                                    else{
                                        layer.msg(res.msg);
                                        layer.close(index);
                                    }
                                },
                                error:function f(res) {
                                    alert("请求失败！状态码：" + res.status);
                                    layer.close(index);
                                }
                            });
                            layer.close(ind);
                        },
                        cancel:function () {
                            $('#search_info_form').css('display', 'none');
                        }
                    })
                    break;
            }
        });

        //监听行工具事件
        table.on('tool(newspaper)', function (obj) {
            var data = obj.data;
            {#--------------------退订弹窗-------------------------#}
            if (obj.event === 'unsubscribe') {
                $("#newspaperID_Unsubscribe").text(data.NewspaperID);
                $("#newspaperName_Unsubscribe").text(data.NewspaperName);
                layer.open({
                    type: 1//0（信息框，默认）1（页面层）2（iframe层）3（加载层）4（tips层)
                    , title: '退订'
                    , shade: 0
                    , area: ['1200px','700px']//定义宽高
                    , offset: ['100px', '300px']
                    , content: $("#add_unsubscribe_form")
                    ,success:function (index, layero) {
                        load_unsubscribe_table('{{ url_for('main_api.get_order_info_by_tags') }}',option_unsubscribe);
                    }
                });
            }
                {#--------------------部门弹窗-------------------------#}
            else if (obj.event === 'subscribe-department') {
                $("#newspaperID_Department").text(data.NewspaperID);
                $("#newspaperName_Department").text(data.NewspaperName);
                layer.open({
                    type: 1//0（信息框，默认）1（页面层）2（iframe层）3（加载层）4（tips层)
                    , title: '部门订阅'
                    ,shade: 0
                    , area: ['1200px','700px']//定义宽高
                    , offset: ['100px', '300px']
                    , content: $("#add_department_form")
                    ,success:function (index, layero) {
                        var table = layui.table;
                        load_table('{{ url_for('main_api.get_department_all_info') }}',option_department);
                        //编辑同步
                        table.on('edit(department_table)', function(result){//lay-verify = department_table，必须定义-=-，用的不是id
                            layer.confirm('是否保存已编辑内容', {btn: ['保存', '取消']}, function (index) {
                                    var data = result.data; //得到所在行所有键值
                                    var Number = data.Number;
                                    var posPattern = /^[1-9]*[1-9][0-9]*$/;
                                    layer.msg('检验输入数据是否有效...');
                                    if(posPattern.test(Number)){
                                        layer.msg('数据有效!');
                                    }else{
                                        result.update({
                                            'DepartmentID': data.DepartmentID,
                                            'DepartmentName': data.DepartmentName,
                                            'Number': ''
                                        });
                                        layer.msg('数据有错!请输入大于0的整数');
                                    }
                                    layer.close(index);
                                }, function (index) {
                                    result.update({
                                        'DepartmentID': data.DepartmentID,
                                        'DepartmentName': data.DepartmentName,
                                        'Number': ''
                                    });
                                    layer.close(index);
                                }

                            );
                        });
                    }
                });
            }
                {#--------------------员工弹窗-------------------------#}
            else if (obj.event === 'subscribe-employee') {
                $("#newspaperID_Employee").text(data.NewspaperID);
                $("#newspaperName_Employee").text(data.NewspaperName);
                layer.open({
                    type: 1//1（页面层）
                    , title: '员工订阅'
                    , shade: 0
                    , area: ['1200px','700px']//定义宽高
                    , offset: ['100px', '300px']
                    , content: $("#add_employee_form")
                    ,success:function (index, layero) {
                        var table = layui.table;
                        var $ = layui.jquery;
                        load_table('{{ url_for('main_api.get_employee_all_data') }}', option_employee);
                        //编辑判定是否是正整数
                        table.on('edit(employee_table)', function (result) {//lay-verify = department_table，必须定义-=-，用的不是id
                            layer.confirm('是否保存已编辑内容', {btn: ['保存', '取消']}, function (index) {
                                    var data = result.data; //得到所在行所有键值
                                    var Number = data.Number;
                                    var posPattern = /^[1-9]*[1-9][0-9]*$/;
                                    layer.msg('检验输入数据是否有效...');
                                    if(posPattern.test(Number)){
                                        layer.msg('数据有效!');
                                    }else{
                                        result.update({
                                            'UserID': data.UserID,
                                            'UserName': data.UserName,
                                            'Number': ''
                                        });
                                        layer.msg('数据有错!请输入大于0的整数');
                                    }
                                    layer.close(index);
                                }, function (index) {
                                    result.update({
                                        'UserID': data.UserID,
                                        'UserName': data.UserName,
                                        'Number': ''
                                    });
                                    layer.close(index);
                                }
                            );
                        });
                    }
                });
            }
        });

        //下拉选择框被选中时触发，将选中的值传出去
        form.on('select',function (data){
            $("#SelectedValue").val(data.elem[data.elem.selectedIndex].text);
        });

        //退订弹窗的搜索栏事件
        $("#seekUnsubscribeData").click(function(){
            var tag_name = $("#SelectedValue").val();
            var keyword = $('#search_unsubscribe_form').val();
            var NewspaperID = $('#newspaperID_Unsubscribe').text();
            $('#search_unsubscribe_form').val("");
            form.render('select');
            $.ajax({
                url: '{{ url_for('main_api.get_order_info_by_newspaper_ID') }}',
                type: 'GET',
                async: true,
                data: {
                    'newspaperID': NewspaperID,
                    'tag': tag_name,
                    'keyword': keyword
                },
                success: function (res) {
                    if (res.code === '200') {
                        var data = res.data;
                        option_unsubscribe['data'] = data;
                        table.render(option_unsubscribe);
                        layer.msg('共查找到' + data.length + '条记录');
                    } else {
                        layer.msg(res.msg);
                    }
                },
                error: function f(res) {
                    alert("请求失败！状态码：" + res.status);
                }
            });
        });

        //部门弹窗的搜索栏事件
        $("#seekDepartmentData").click(function(){
            var tag_name = $("#SelectedValue").val();
            var keyword = $('#search_department_form').val();
            $('#search_department_form').val("");
            form.render('select');
            $.ajax({
                url: '{{ url_for('main_api.get_department_info_by_tags') }}',
                type: 'GET',
                async: true,
                data: {'tag': tag_name, 'keyword': keyword},
                success: function (res) {
                    if (res.code === '200') {
                        var data = res.data;
                        option_department['data'] = data;
                        table.render(option_department);
                        layer.msg('共查找到' + data.length + '条记录');
                    } else {
                        layer.msg(res.msg);
                    }
                },
                error: function f(res) {
                    alert("请求失败！状态码：" + res.status);
                }
            });
        });

        //员工弹窗的搜索栏事件
        $("#seekEmployeeData").click(function(){
            var tag_name = $("#SelectedValue").val();
            var keyword = $('#search_employee_form').val();
            $('#search_employee_form').val("");
            form.render('select');
            $.ajax({
                url: '{{ url_for('main_api.get_employee_info_by_tags') }}',
                type: 'GET',
                async: true,
                data: {'tag': tag_name, 'keyword': keyword},
                success: function (res) {
                    if (res.code === '200') {
                        var data = res.data;
                        option_employee['data'] = data;
                        table.render(option_employee);
                        layer.msg('共查找到' + data.length + '条记录');
                    } else {
                        layer.msg(res.msg);
                    }
                },
                error: function f(res) {
                    alert("请求失败！状态码：" + res.status);
                }
            });
        });

        {#退订按钮#}
        $("#unsubscribe_button").click(function(){
            var checkStatus = table.checkStatus('Unsubscribe_t')
                ,data = checkStatus.data;
            var NewspaperID = $("#newspaperID_Unsubscribe").text()
            var Data = [];
            for (var i = 0; i < data.length; i++) {
                mydic = {};
                mydic["data"] = {};
                mydic["data"]['CreateTime'] = data[i]['CreateTime'];
                mydic["data"]['DepartmentID'] = data[i]['DepartmentID'];
                mydic["data"]['DepartmentName'] = data[i]['DepartmentName'];
                mydic["data"]['Number'] = data[i]['Number'];
                mydic["data"]['UserID'] = data[i]['UserID'];
                mydic["data"]['UserName'] = data[i]['UserName'];
                mydic["data"]['NewspaperID'] = NewspaperID;
                Data[i] = mydic;
            }
            $.ajax({
                url: '{{ url_for('main_api.delete_order_info_list')}}',
                type: 'POST',
                async: true,
                data: {'datas':JSON.stringify(Data)},
                success: function (res) {
                    if (res.code === '200') {
                        layer.msg('退订成功！！！');
                        load_table('{{ url_for('main_api.get_order_info_by_tags') }}',option_unsubscribe);
                    } else {
                        layer.msg(res.msg);
                    }
                },
                error: function f(res) {
                    alert("请求失败！状态码：" + res.status);
                }
            });
        });

        {#部门订阅按钮#}
        $("#department_button").click(function(){
            var checkStatus = table.checkStatus('Department_t')
                ,data = checkStatus.data;
            var NewspaperID = $("#newspaperID_Department").text()
            var Data = [];
            for (var i = 0; i < data.length; i++) {
                mydic = {};
                mydic["data"] = {};
                mydic["data"]['CreateTime'] = data[i]['CreateTime'];
                mydic["data"]['DepartmentID'] = data[i]['DepartmentID'];
                mydic["data"]['DepartmentName'] = data[i]['DepartmentName'];
                mydic["data"]['Number'] = data[i]['Number'];
                mydic["data"]['IsDeleted'] = data[i]['IsDeleted'];
                mydic["data"]['NewspaperID'] = NewspaperID;
                Data[i] = mydic;
            }
            for (var i = 0; i < data.length; i++) {
                if(data[i]['Number'] == undefined){
                    layer.msg('有人的订阅的数量尚未输入，请输入后订阅');
                    return;
                }
            }
            $.ajax({
                url: '{{ url_for('main_api.add_department_order_info')}}',
                type: 'POST',
                async: true,
                data: {'datas':JSON.stringify(Data)},
                success: function (res) {
                    if (res.code === '200') {
                        load_table('{{ url_for('main_api.get_department_all_info') }}',option_department);
                        layer.msg('订阅成功！');
                    } else {
                        layer.msg(res.msg);
                    }
                },
                error: function f(res) {
                    alert("请求失败！状态码：" + res.status);
                }
            });
        });

        {#员工订阅按钮#}
        $("#employee_button").click(function(){
            var checkStatus = table.checkStatus('Employee_t')
                ,data = checkStatus.data;
            var NewspaperID = $("#newspaperID_Employee").text()
            var Data = [];
            for (var i = 0; i < data.length; i++) {
                mydic = {};
                mydic["data"] = {};
                mydic["data"]['CreateTime'] = data[i]['CreateTime'];
                mydic["data"]['UserID'] = data[i]['UserID'];
                mydic["data"]['UserName'] = data[i]['UserName'];
                mydic["data"]['number'] = data[i]['Number'];
                mydic["data"]['IsDeleted'] = data[i]['IsDeleted'];
                mydic["data"]['NewspaperID'] = NewspaperID;
                Data[i] = mydic;
            }
            for (var i = 0; i < data.length; i++) {
                if(data[i]['Number'] == undefined){
                    layer.msg('订阅数量尚未输入，请输入后再订阅');
                    return;
                }
            }
            $.ajax({
                url: '{{ url_for('main_api.add_employee_order_info')}}',
                type: 'POST',
                async: true,
                data: {'datas':JSON.stringify(Data)},
                success: function (res) {
                    if (res.code === '200') {
                        load_table('{{ url_for('main_api.get_employee_all_data') }}',option_employee);
                        layer.msg('添加用户信息成功!');
                    } else {
                        layer.msg(res.msg);
                    }
                },
                error: function f(res) {
                    alert("请求失败！状态码：" + res.status);
                }
            });
        });

    </script>
{% endblock %}